Skip to content

fix(cli): resolve relative paths before computing file URI - #3

Merged
bartrosa merged 1 commit into
mainfrom
cursor/critical-correctness-issues-d028
May 23, 2026
Merged

fix(cli): resolve relative paths before computing file URI#3
bartrosa merged 1 commit into
mainfrom
cursor/critical-correctness-issues-d028

Conversation

@cursor

@cursor cursor Bot commented May 5, 2026

Copy link
Copy Markdown

Bug & impact

The bigos parse CLI crashed with ValueError: relative path can't be expressed as a file URI whenever the user passed a relative path — e.g. the exact invocation shown in the README quickstart:

bigos parse contract.pdf --format=md

Reproduction (slightly trimmed):

$ bigos parse contract.pdf --format=md
Traceback (most recent call last):
  ...
  File "/workspace/src/bigos/cli.py", line 84, in parse
    source = Source(uri=path.as_uri(), mime_type=mime, sha256=sha256_file(path))
                        ^^^^^^^^^^^^^
  File ".../pathlib.py", line 467, in as_uri
    raise ValueError("relative path can't be expressed as a file URI")
ValueError: relative path can't be expressed as a file URI

Impact: every documented quickstart invocation from a normal working directory aborts before any parsing happens. The CLI is the primary entry point of the package, so this is high blast-radius user-facing breakage.

Root cause

Path.as_uri() is only defined for absolute paths. Typer/Click's default Path parameter (resolve_path=False) hands the user-supplied string through verbatim, so path in the parse command stayed relative. The as_uri() call therefore raised on any relative input.

Fix

src/bigos/cli.py: resolve the input path to absolute (path.resolve()) before calling as_uri(), and reuse the resolved path for sha256_file() so the URI and the hashed bytes always refer to the same canonical location.

-    mime = mimetypes.guess_type(path)[0] or "application/octet-stream"
-    source = Source(uri=path.as_uri(), mime_type=mime, sha256=sha256_file(path))
+    mime = mimetypes.guess_type(path)[0] or "application/octet-stream"
+    abs_path = path.resolve()
+    source = Source(uri=abs_path.as_uri(), mime_type=mime, sha256=sha256_file(abs_path))

Validation

  • New regression test test_cli_relative_path_does_not_crash_with_value_error in tests/test_cli.py invokes the CLI through Typer's CliRunner with a relative path (using a stub backend) and asserts the resulting Source.uri is a valid absolute file:// URI.
  • Full test suite: pytest -m "not slow" → 54 passed; pytest tests/test_cli.py (incl. slow Docling parse tests) → 6 passed.
  • No other behavioural changes; the fix is a one-line .resolve() plus a passthrough.
Open in Web View Automation 

bigos parse <relative.pdf> raised ValueError: 'relative path can't be
expressed as a file URI' because Path.as_uri() refuses any non-absolute
path. The README's quickstart example (bigos parse contract.pdf) hit
this on every invocation from a normal cwd.

Resolve the user-supplied path to absolute before calling as_uri() and
use the resolved path for hashing too (so symlinks/canonical paths flow
into the cache key consistently).

Add a regression test that runs the parse command with a relative path
through Typer's CliRunner and asserts the resulting Source.uri is an
absolute file:// URI.

Co-authored-by: Bartłomiej Rosa <bartrosa@users.noreply.github.com>
@bartrosa
bartrosa marked this pull request as ready for review May 23, 2026 12:45
@bartrosa
bartrosa merged commit aea882a into main May 23, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants